<template>
  <div class="lists">
    <el-table
      :data="cateListData"
      style="width: 100%; margin-bottom: 20px"
      row-key="id"
      border
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
      height="510px"
    >
      <el-table-column prop="id" label="编号" sortable width="180">
      </el-table-column>
      <el-table-column prop="catename" label="名称" sortable width="180">
      </el-table-column>
      <el-table-column prop="img" label="图片">
        <template slot-scope="scope">
          <img
            v-show="scope.row.img != ''"
            :src="baseURL + scope.row.img"
            alt=""
            srcset=""
            class="goodsImg"
          />
        </template>
      </el-table-column>
      <el-table-column prop="status" label="状态">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.status == 1">启用</el-tag>
          <el-tag v-if="scope.row.status == 2" type="danger">禁用</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="address" label="操作">
        <template slot-scope="scope">
          <el-button type="primary" @click="editCategory(scope.row.id)"
            >编辑</el-button
          >
          <el-button type="danger" @click="deleteCategory(scope.row.id)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { getCateDelete } from "../../../request/api";
export default {
  props: ["dialog", "cateListData","refreshList"],
  data() {
    return {};
  },
  methods: {
    editCategory(id) {
      this.$emit("editCategory", id);
    },
    // 删除
    deleteCategory(id) {
      this.$confirm("是否删除该菜单?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
      }).then(
        () => {
          getCateDelete({ id }).then(
            (res) => {
              if (res.data.code == 200) {
                this.$message.success("删除成功");
                this.dialog.isShowDialog = false;
                // 刷新数据
                this.refreshList()
              }
            },
            (err) => err
          );
        },
        (err) => err
      );
    },
  },
};
</script>

<style>
.goodsImg {
  width: 100px;
  height: 100px;
}
</style>